<template>
	<view class="imagePage">
		
		<!-- 推荐好友 -->
		<view class="recommend" v-if="type == 1">
			<view class="" style="margin: 100rpx auto !important;text-align: center;">
				团洗商户入驻
			</view>
			<image class="codeTwo" :src="pageData" mode="" @longpress="downloadImage"></image>
			<view class="title">
				<view class="">专属邀请码</view>
				<view class="" style="width: 500rpx;height: 2rpx;background: darkgray;margin: 60rpx 0 30rpx;"></view>
				<view class="">扫码邀请>推广有礼>权益享受</view>
				<view class="">长按保存到相册</view>
			</view>
			<view class="title2" >
				成为商户后可享受权益
			</view>
		</view>
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				image: this.$base.smallimgUrl,
				type: 1, // type  1代表是 推荐好友  2代表是 pk胜  3代表是  pk负
				pageData: '',
				userInfo: uni.getStorageSync('userInfo'),
				share: {},
				isType:0,
				img_hb:''
			};
		},
		onLoad(el) {
			this.type = el.type
			this.isType = el.isType
			if(this.type == 1){
				this.getPageData()
			}
		},
		onShareAppMessage() {
			return {
				title: this.share.title,
				path: this.share.path,
				imageUrl: this.share.imageUrl,
				desc: this.share.desc,
				content: this.share.content,
				success(res) {
					this.$utils.toast('分享成功')
					this.share = {}
					console.log(res)
				},
				fail(res) {
					this.$utils.toast('分享失败')
				}
			}
		},
		methods: {
			// 推荐好友
			getPageData(){
				let that = this
				that.$api.inviteFriends().then(res => {
					that.pageData = res.data.data.img
					// console.log(that.pageData,'that.pageData')
					that.img_hb = res.data.data.img_hb
				})
			},
			// 点击下载图片
			downloadImage(){
				let that = this
				uni.downloadFile({
					url: that.img_hb,
					success(res) {
						let tempFilePath = res.tempFilePath
						uni.saveImageToPhotosAlbum({
							filePath: tempFilePath,
							success(res1){
								that.$utils.toast('图片生成成功')
							},
							fail(err){
								that.$utils.toast('图片生成失败')
							}
						})
					}
				})
			},
		}
	}
</script>

<style lang="less">
	.title2{
		position: absolute;
		width: 500rpx;
		top: 66%;
		left: 18%;
		text-align: center;
		background: gainsboro;color: gray;
		padding: 40rpx 60rpx;
		view{
			height: 50rpx;
			line-height: 50rpx;
			font-size: 28rpx;
		}
	}
	.imagePage{
		.recommend{
			width: 100vw;
			height: 100vh;
			.title{
				position: absolute;
				width: 500rpx;
				top: 46%;
				left: 18%;
				text-align: center;
				view{
					height: 50rpx;
					line-height: 50rpx;
					font-size: 28rpx;
				}
			}
			image{
				width: 100%;
				height: 100%;
			}
			.codeTwo{
				width: 450rpx;
				height: 450rpx;
				position: absolute;
				top: 12%;
				left: 21%;
			}
			.btn{
				width: 80%;
				height: 96rpx;
				line-height: 96rpx;
				text-align: center;
				border-radius: 16rpx;
				font-size: 28rpx;
				font-weight: 500;
				position: fixed;
			}
			.invitation{
				background: #1FC064;
				color: #fff;
				bottom: 200rpx;
				left: 50%;
				transform: translateX(-50%);
			}
			.generate{
				background: #DCDCDC;
				color: #7F8084;
				bottom: 70rpx;
				left: 50%;
				transform: translateX(-50%);
			}
		}
		
		.PKWin,.PKNegative{
			width: 100vw;
			height: 100vh;
			image{
				width: 100%;
				height: 100%;
			}
			.btn{
				width: 80%;
				height: 96rpx;
				line-height: 96rpx;
				text-align: center;
				border-radius: 96rpx;
				font-size: 28rpx;
				font-weight: 500;
				position: fixed;
				background: #000;
				color: #fff;
				bottom: 240rpx;
				left: 50%;
				transform: translateX(-50%);
			}
		}

	}
</style>
